package com.xs.pojo;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Log {
    private Integer id;
    private String user_name;//姓名
    private String sex;//性别
    private String home;//书名
    private String phon;//电话
    private Date head_time;//借出时间
    private Date end_time;//归还时间
    //逻辑视图
    private String statusStr;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUser_name() {
        return user_name;
    }

    public void setUser_name(String user_name) {
        this.user_name = user_name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getHome() {
        return home;
    }

    public void setHome(String home) {
        this.home = home;
    }

    public String getPhon() {
        return phon;
    }

    public void setPhon(String phon) {
        this.phon = phon;
    }

    public Date getHead_time() {
        return head_time;
    }

    public void setHead_time(Date head_time) {
        this.head_time = head_time;
    }

    public Date getEnd_time() {
        return end_time;
    }

    public void setEnd_time(Date end_time) {
        this.end_time = end_time;
    }

    //逻辑视图
    public String getStatusStr() throws ParseException {
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = formatter.format(System.currentTimeMillis());
        Date parse = formatter.parse(format);

        if (parse.compareTo(end_time)>=0){
            return "已过期";
        }
        return "生效中";
    }

    public void setStatusStr(String statusStr)throws ParseException {
        this.statusStr = statusStr;
    }


    @Override
    public String toString() {
        return "Log{" +
                "id=" + id +
                ", user_name='" + user_name + '\'' +
                ", sex='" + sex + '\'' +
                ", book_name='" + home + '\'' +
                ", phon='" + phon + '\'' +
                ", head_time=" + head_time +
                ", end_time=" + end_time +
                '}';
    }
}
